/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.brain.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.brain.entity.BRankDic;
import com.thinkgem.jeesite.modules.brain.service.BRankDicService;

/**
 * 排位字典Controller
 * @author 程展峰
 * @version 2021-09-18
 */
@Controller
@RequestMapping(value = "${adminPath}/brain/bRankDic")
public class BRankDicController extends BaseController {

	@Autowired
	private BRankDicService bRankDicService;
	
	@ModelAttribute
	public BRankDic get(@RequestParam(required=false) String id) {
		BRankDic entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bRankDicService.get(id);
		}
		if (entity == null){
			entity = new BRankDic();
		}
		return entity;
	}
	
	@RequiresPermissions("brain:bRankDic:view")
	@RequestMapping(value = {"list", ""})
	public String list(BRankDic bRankDic, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BRankDic> page = bRankDicService.findPage(new Page<BRankDic>(request, response), bRankDic); 
		model.addAttribute("page", page);
		return "modules/brain/bRankDicList";
	}

	@RequiresPermissions("brain:bRankDic:view")
	@RequestMapping(value = "form")
	public String form(BRankDic bRankDic, Model model) {
		model.addAttribute("bRankDic", bRankDic);
		return "modules/brain/bRankDicForm";
	}

	@RequiresPermissions("brain:bRankDic:edit")
	@RequestMapping(value = "save")
	public String save(BRankDic bRankDic, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bRankDic)){
			return form(bRankDic, model);
		}
		bRankDicService.save(bRankDic);
		addMessage(redirectAttributes, "保存排位字典成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bRankDic/?repage";
	}
	
	@RequiresPermissions("brain:bRankDic:edit")
	@RequestMapping(value = "delete")
	public String delete(BRankDic bRankDic, RedirectAttributes redirectAttributes) {
		bRankDicService.delete(bRankDic);
		addMessage(redirectAttributes, "删除排位字典成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bRankDic/?repage";
	}

}